package demo.IOInputOutput;

import java.io.*;
import java.nio.file.Files;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/11-08-11-19:18
 * @Description：demo.IOInputOutput
 */
public class downloadFile {
    public static void main(String[] args){

        File targetFile = new File("C:\\Users\\hjy\\Pictures\\jjy2.jpg");
        File newFile = new File("D:\\qq文件\\jjy2.jpg");
        FileInputStream in = null;
        FileOutputStream out = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            if(!newFile.exists()) {
                newFile.createNewFile();
            }
            in = new FileInputStream(targetFile);
            out = new FileOutputStream(newFile);

            bos = new BufferedOutputStream(out);
            bis = new BufferedInputStream(in);

            int len = -1;
            while ((len = bis.read()) != -1){
                out.write(len);
            }
            out.flush();

//            byte[] b = new byte[1024];
//            while((len = in.read(b)) != -1){
//                out.write(b,0,len);
//            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bis.close();
                bos.close();
                if(in != null) {
                    in.close();
                }
                if(out != null){
                    out.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}